/**
 * \file TimeMeasure_Win32.h
 * \brief TimeMeasure definition class for windows.  Object used to measure time (even short)
 * \author Edouard ROGE
 * \date 07 august 2012
 */

#ifndef _TIMEMEASURE_WIN32_
#define _TIMEMEASURE_WIN32_

#include <vector>
#include "Core/Memory/HeapObject.h"
#include "Core/Thread/Mutex.h"

namespace Core
{
	namespace Time
	{
		/**
		 * \class TimeMeasure
		 * \brief Measure elapsed time between one moment and another
		 */
		class TimeMeasure : public Memory::HeapObject
		{
		public:
			/**
			 * \fn TimeMeasure();
			 * \brief Default constructor
			 */
			TimeMeasure();

			/**
			 * \fn ~TimeMeasure();
			 * \brief Destructor
			 */
			~TimeMeasure();

			/**
			 * \fn uint32 AddMeasure();
			 * \return created index of the new time measure
			 * \brief Create and add a new time measure
			 */
			uint32 AddMeasure();

			/**
			 * \fn void Start(uint32 _iIndex);
			 * \param _iIndex index of the time measure to start
			 * \brief Start the measure of time for the index in parameter
			 */
			void Start(uint32 _iIndex);

			/**
			 * \fn void Stop(uint32 _iIndex);
			 * \param _iIndex index of the time measure to stop
			 * \brief Stop the measure of the time for the index in parameter
			 */
			void Stop(uint32 _iIndex);

			/**
			 * \fn float GetMeasure(int32 _iIndex) const;
			 * \param _iIndex index of the time measure to get the elapsed time between its start and its stop
			 * \return time elapsed
			 * \brief Compute elapsed time in milliseconds between start and stop
			 */
			float GetMeasure(int32 _iIndex) const;

		private:

			/** Proc frequency */
			int64 m_dwFrequency;

			/** Stored measured times, 2n=start time index 'n', 2n+1=end time index 'n'*/
			std::vector<int64> m_Measures;

			/** Mutex */
			Thread::Mutex m_Mutex;
		};
	}
}

#endif // _TIMEMEASURE_
